package com.hnjd.service.imp;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hnjd.dao.AdminDao;
import com.hnjd.entity.Admins;
import com.hnjd.entity.Orders;
import com.hnjd.entity.Types;
import com.hnjd.entity.User;
import com.hnjd.entity.Users;
import com.hnjd.service.IAdminService;

@Service
public class AdminService implements IAdminService{

	@Autowired
	private AdminDao dao;

	@Override
	public List<Admins> login(Admins ad) {
		// TODO Auto-generated method stub
		return dao.login(ad);
	}
	
	@Override
	public List<Admins> adminList() {
		// TODO Auto-generated method stub
		return dao.adminList();
	}
	
	@Override
	public Integer adminReset(Admins admins) {
		// TODO Auto-generated method stub
		return dao.adminReset(admins);
	}

	@Override
	public Integer adminAdd(Admins admins) {
		// TODO Auto-generated method stub
		return dao.adminAdd(admins);
	}
	
	@Override
	public Integer adminDelete(Integer id) {
		// TODO Auto-generated method stub
		return dao.adminDelete(id);
	}
	
	public List<Orders> orderListByStatus(Integer status) {
		// TODO Auto-generated method stub
		List<Orders> ordersList = dao.ordersListByStatus(status);
		ordersList.forEach(order->{
			Integer orderId = order.getId();
			order.setItemList(dao.itemList(orderId));
			Integer userId = order.getUserId();
			order.setUser(dao.getUserById(userId));
		});		
		return ordersList;
	}

	@Override
	public List<Orders> ordersList() {
		// TODO Auto-generated method stub
		List<Orders> ordersList = dao.ordersList();
		ordersList.forEach(order->{
			Integer orderId = order.getId();
			order.setItemList(dao.itemList(orderId));
			Integer userId = order.getUserId();
			order.setUser(dao.getUserById(userId));
		});		
		return ordersList;
	}

	@Override
	public Integer orderDelete(Integer id) {
		// TODO Auto-generated method stub
		return dao.orderDelete(id);
	}

	@Override
	public User getUserById(Integer userId) {
		// TODO Auto-generated method stub
		return dao.getUserById(userId);
	}

	@Override
	public Integer orderUpdate(Integer status, Integer id) {
		// TODO Auto-generated method stub
		return dao.orderUpdate(status, id);
	}

	@Override
	public List<Types> typeList() {
		// TODO Auto-generated method stub
		return dao.typeList();
	}

	@Override
	public Integer typeAdd(Types types) {
		// TODO Auto-generated method stub
		return dao.typeAdd(types);
	}

	@Override
	public Types typeEditById(Integer id) {
		// TODO Auto-generated method stub
		return dao.typeEditById(id);
	}

	@Override
	public Integer typeUpdate(Types types) {
		// TODO Auto-generated method stub
		return dao.typeUpdate(types);
	}

	@Override
	public Integer typeDelete(Integer id) {
		// TODO Auto-generated method stub
		return dao.typeDelete(id);
	}

	@Override
	public List<Users> userList() {
		// TODO Auto-generated method stub
		return dao.userList();
	}

	@Override
	public Integer userAdd(Users users) {
		// TODO Auto-generated method stub
		return dao.userAdd(users);
	}

	@Override
	public Users userEdit(Integer id) {
		// TODO Auto-generated method stub
		return dao.userEdit(id);
	}

	@Override
	public Integer userUpdate(Users users) {
		// TODO Auto-generated method stub
		return dao.userUpdate(users);
	}

	@Override
	public Integer userDelete(Integer id) {
		// TODO Auto-generated method stub
		return dao.userDelete(id);
	}

	@Override
	public Integer userReset(Users users) {
		// TODO Auto-generated method stub
		return dao.userReset(users);
	}


}
